feat(apigee): allow injecting credentials into ApigeeLlm#4722
feat(apigee): allow injecting credentials into ApigeeLlm#4722polar3130 wants to merge 7 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
Response from ADK Triaging Agent Hello @polar3130, thank you for your contribution! It looks like the Contributor License Agreement (CLA) check has failed. Before we can merge this PR, you'll need to sign the CLA. You can find more information in the "checks" section at the bottom of the pull request. Thanks! |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the ApigeeLlm client's authentication mechanism by explicitly requesting the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request successfully implements the requested feature to add the userinfo.email scope for tokeninfo user identification in ApigeeLlm.api_client. The changes are well-contained within the ApigeeLlm class and do not impact other parts of the codebase. A new unit test has been added to verify the correct behavior, which is a good practice.
| assert 'https://www.googleapis.com/auth/userinfo.email' in _APIGEE_SCOPES | ||
| assert 'https://www.googleapis.com/auth/cloud-platform' in _APIGEE_SCOPES |
There was a problem hiding this comment.
These assertions are redundant. The test already verifies that mock_auth_default is called with _APIGEE_SCOPES on line 664. If the _APIGEE_SCOPES constant itself is incorrectly defined in apigee_llm.py, that would be a bug in the constant's definition, not in how it's used by api_client. Removing these lines will make the test more concise and focused on the behavior of api_client.
c412162 to
59c654f
Compare
|
Hi @polar3130 , Thank you for your contribution through this pull request! This PR has merge conflicts that require changes from your end. Could you please rebase your branch with the latest main branch to address these? Once this is complete, please let us know so we can proceed with the review. |
ApigeeLlm now explicitly requests the userinfo.email OAuth scope alongside cloud-platform when creating credentials. This enables Apigee Gateway to identify callers via Google's tokeninfo API when using Service Account key authentication. Fixes google#4721
59c654f to
d79b22c
Compare
|
Hi @rohityan , Thanks for letting me know! I've rebased onto the latest main and resolved the conflict. Also addressed the review comment about redundant assertions in the test. Ready for review. |
|
Hi @polar3130 , please fix formatting errors. You can use autoformat.sh |
9770464 to
1b96b09
Compare
|
Hi @rohityan , Thanks for the feedback! Fixed the formatting errors using autoformat.sh. |
|
Hi @polar3130 , can you fix the failing unit tests |
Add autouse fixture to mock google.auth.default across all apigee_llm tests, preventing DefaultCredentialsError in CI environments without Application Default Credentials.
|
Hi @rohityan, I've fixed the failing unit tests. The issue was that I added an Could you approve the CI workflow run so the tests can be verified on CI as well? Thanks! |
|
Hi @rohityan, friendly ping on this PR. |
mdomingo22
left a comment
There was a problem hiding this comment.
Sorry about the delay.
I'd like to keep the default auth mechanisms as is. Can you instead modify the init to receive credentials: google.auth.credentials.Credentials | None = None and pass those along?
The underlying client, https://googleapis.github.io/python-genai/genai.html#genai.client.Client, warns about using credentials when using Gemini Developer API
Per reviewer feedback, drop the internal google.auth.default() call and the _APIGEE_SCOPES constant. Instead, expose an opt-in credentials parameter on ApigeeLlm.__init__ that is forwarded to genai.Client when provided. When omitted, the credentials kwarg is not forwarded at all, preserving the default genai.Client auth flow (and avoiding its Gemini Developer API warning about credentials usage). Callers needing additional OAuth scopes (e.g., userinfo.email for Apigee tokeninfo identification, the original google#4721 use case) can now construct credentials with their preferred scopes and inject them.
…rinfo-email-scope
|
Hi @mdomingo22, thanks for the feedback! I've updated the PR per your suggestion. Changes
Users who need additional scopes (e.g., All 57 unit tests pass locally. Please take another look when you have a chance. |
Summary
credentials: google.auth.credentials.Credentials | Noneparameter toApigeeLlm.__init__.genai.Client. When omitted, thecredentialskwarg is not forwarded at all, so the defaultgenai.Clientauth flow is fully preserved (including avoiding the Gemini Developer API credentials warning).google.auth.default()call and_APIGEE_SCOPESconstant. The default auth mechanism is no longer modified byApigeeLlm.userinfo.emailfor Apigee tokeninfo identification, the original ApigeeLlm: Add userinfo.email scope for Apigee Gateway tokeninfo user identification #4721 use case) can now construct credentials with their preferred scopes and inject them.Fixes #4721
Test plan
test_api_client_passes_credentials_when_providedverifying credentials are forwarded togenai.Client.test_api_client_omits_credentials_when_not_providedverifying the kwarg is not forwarded when unset.test_apigee_llm.pypass.